Writing an Interface
Tiny Server Program
This week’s focus was on building an interface between my computer and the board, and at the heart of that interface is a small server program. It is in charge of working between the hardware and whatever user interface I build, serving as a bridge between UI interaction and the hardware.Since I need time to work on the final project, this week's time was actually quite tight. So I just want to get this quickly over with and focus on things that are expected to be time consuming. The learning process is fun though, and I can clearly sense the kind of potential this application could have to integrate functionality all together to something that is closer to consumer product.
The server program would in theory:- Opens a connection to the board (over serial).
- Listens for incoming data and parses it into meaningful messages.
- Responds to simple commands from the UI/Python side (for example: read a sensor, toggle an output, or report status).It could do so many things, but this week I'm only doing a small demo of its power.
- Makes it easy to swap or extend front-end interfaces without touching the low-level board code.
Making the Board Work: From Bare PCB to Talking Device
Before I could worry about user interfaces, I needed to make sure the board actually worked and could talk back to my computer. I'm using the board I made before and wrote a few simple function and had it tested. Here's the code: Board Message Program DownloadDemo: Board
UI and Python Program
Given the simplicity of the UI I had in mind, this simple html page took my 5 minutes to write. It is actually the script part that took most of the time.(I had ChatGPT helped me to debug)
Some Preparation Work:
Other than the typical debugging process I encountered, one thing that's worthy noting is if the port is being used, we cannot upload the board code via Arduino. Obviously the server needs to be closed so that others can use it. Took me a while to figure this out.Other than that, I'd say the whole development work was pretty smoooth.